package com.taotao.portal.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.taotao.common.HttpClientUtil;
import com.taotao.common.JsonUtils;
import com.taotao.common.TaotaoResult;
import com.taotao.pojo.TbContent;
import com.taotao.portal.service.ContentService;

@Service
public class ContentServiceImpl implements ContentService {
	@Value(value="${REST_BASE_PATH}")
	private String REST_BASE_PATH;
	@Value(value="${CONTENT_PATH}")
	private String CONTENT_PATH;
	@Override
	public String getContentList() {
		//调用服务层的服务
		String doGet = HttpClientUtil.doGet(REST_BASE_PATH+CONTENT_PATH);
		try {
			TaotaoResult result=TaotaoResult.formatToList(doGet, TbContent.class);
			List<TbContent> list=(List<TbContent>) result.getData();
			List<Map> listMap=new ArrayList<>();
			for(TbContent content:list){
				Map<String,Object> map=new HashMap<>();
				map.put("src", content.getPic());
				map.put("srcB", content.getPic2());
				map.put("height", 240);
				map.put("heightB", 240);
				map.put("width", 670);
				map.put("widthB", 540);
				map.put("href", content.getUrl());
				map.put("alt", content.getSubTitle());
				listMap.add(map);
			}
			return JsonUtils.objectToJson(listMap);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
